package com.example.demo.web.controller;

import com.example.demo.constant.RequestUrl;
import com.example.demo.param.OperatorFindAllParam;
import com.example.demo.param.OperatorSaveParam;
import com.example.demo.param.OperatorUpdateParam;
import com.example.demo.service.OperatorService;
import com.example.demo.vo.ApiResult;
import com.example.demo.vo.OperatorPageVO;
import com.example.demo.vo.OperatorVO;
import com.example.demo.vo.PageVO;
import com.example.demo.web.api.OperatorApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = RequestUrl.API + RequestUrl.OPERATOR)
public class OperatorController implements OperatorApi {

    @Autowired
    private OperatorService operatorService;

    @Override
    @PostMapping()
    public ApiResult<Long> save(@RequestBody OperatorSaveParam operatorSaveParam) throws Exception {
        return operatorService.save(operatorSaveParam);
    }

    @Override
    @PutMapping()
    public ApiResult<Long> update(@RequestBody OperatorUpdateParam operatorUpdateParam) throws Exception {
        return operatorService.update(operatorUpdateParam);
    }

    @Override
    @GetMapping(value = "/{id}")
    public ApiResult<OperatorVO> findById(@PathVariable("id") Long id) throws Exception {
        return operatorService.findById(id);
    }

    @Override
    @GetMapping()
    public ApiResult<PageVO<OperatorPageVO>> findAll(OperatorFindAllParam operatorFindAllParam) throws Exception {
        return operatorService.findAll(operatorFindAllParam);
    }

    @Override
    @DeleteMapping(value = "/{id}")
    public ApiResult<Long> deleteById(@PathVariable("id") Long id) throws Exception {
        return operatorService.deleteById(id);
    }
}
